package com.sheep.Pattern.Singleton.doubleCheckLock;
/**
 * @author sheep
 *  双重检查锁
 *  优点: 线程安全 效率高
 *  缺点: 可读性差 不怎么用
 */
public class DoubleCheckLock {
    private static DoubleCheckLock doubleCheckLock;
    private DoubleCheckLock(){}
    public static DoubleCheckLock getInstance(){
        if(doubleCheckLock == null){
            // 同步代码块 锁的是类的class对象
            synchronized (DoubleCheckLock.class){
                if(doubleCheckLock == null){
                    doubleCheckLock = new DoubleCheckLock();
                }
            }
        }
        return doubleCheckLock;
    }
}
